package miniBanco.Handler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;

import basics.TableManager;
import miniBanco.Core.LogBO;
import miniBanco.Gui.LogGridPanel;
import miniBanco.Mapper.LogDAO;

public class HandlerLog {
	
	private static HandlerLog instance = null;
	LogGridPanel logGridPanel;
	private JFrame jPopUpFrame;
	private LogDAO LogDAO;
	private LogBO LogBO;
	private HandlerLog() {
		LogDAO = new LogDAO();
		LogBO = new LogBO();
		LogBO.setDao(LogDAO);
	
	}

	
    public static HandlerLog getInstance() {
      if(instance == null) {
         instance = new HandlerLog();
      }
      return instance;
    }
    

    public LogGridPanel VerLog()
    {
    	logGridPanel = new LogGridPanel();
    	
    	logGridPanel.getGird().Refresh(LogBO.getAllLog());
    	logGridPanel.getBtnRefrescar().addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Refresh();
			}
		});
    	logGridPanel.getBtnBorrarLog().addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				TableManager.getInstance().dropLogTable();
				TableManager.getInstance().createLogTable();
				Refresh();
			}
		});	
    	return logGridPanel;

    }
	private void Refresh() {
		logGridPanel.getGird().Refresh(LogBO.getAllLog());
	}
    public void OpenLogPopup()
    {
		jPopUpFrame = new JFrame();
		jPopUpFrame.setBounds(0,0,500,500);
		jPopUpFrame.add(VerLog());
		jPopUpFrame.setVisible(true);
		
    }
	
	
}
